package logic

import (
	"ck/ckrpc/ckrpc"
	"ck/ckrpc/internal/svc"
	"ck/models/mysql"
	"ck/pkg"
	"context"
	"github.com/zeromicro/go-zero/core/logx"
)

type RegisterLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RegisterLogic) Register(in *ckrpc.RegisterRequest) (*ckrpc.RegisterResponse, error) {
	// todo: add your logic here and delete this line
	user := mysql.User{
		Account:  in.Account,
		Password: pkg.Md5str(in.Password),
	}
	mysql.DB.Debug().Create(&user)

	return &ckrpc.RegisterResponse{
		UserId: int64(user.ID),
	}, nil
}
